package com.dc.bobaoge.project.v3.to.v2.business.core;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreUser;
import com.dc.bobaoge.project.base.core.old.mapper.OldCoreUserMapper;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import com.own.business.system.user.mapper.SystemUserInfoMapper;
import com.own.component.common.exception.BusinessSimpleException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * SystemUserPhoneResolveMethod
 *
 * @author chenxueli
 * @date 2024-01-16 17:35:00
 */
@Slf4j
@Component
public class SystemUserPhoneResolveMethod implements ResolveMethod {

    @Resource
    private SystemUserInfoMapper systemUserInfoMapper;

    @Resource
    private OldCoreUserMapper oldCoreUserMapper;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        var userInfo = systemUserInfoMapper.selectById(trigger.getTargetId());
        if (userInfo == null) {
            throw new BusinessSimpleException("用户详细信息不存在" + trigger.getTargetId());
        }
        // 执行修改操作
        var wrapper = new LambdaUpdateWrapper<OldCoreUser>()
                .set(OldCoreUser::getUserPhone, userInfo.getPhone())
                .eq(OldCoreUser::getUserId, userInfo.getFkUserId());
        oldCoreUserMapper.update(wrapper);
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "system_user_phone";
    }

}
